#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>


int gval = 100;

void* threadStart(void* args)
{
    while(1)
    {
        sleep(1);
        std::cout << "I am new thread, pid: " << getpid() << ", gval: " << gval << ", &gval: " << &gval << std::endl;
    }
}

int main()
{
    // 启动新线程
    pthread_t tid;
    pthread_create(&tid, nullptr, threadStart, (void*)"thread-new");

    // 主线程
    while(1)
    {
        std::cout << "I am main thread, pid: " << getpid() << ", gval: " << gval << ", &gval: " << &gval << std::endl;
        gval++; // 修改

        sleep(1);
    }
    return 0;
}